import axios from 'axios';
import * as constants from './constants';

const changeDetail = (data) => ({
  type: constants.GET_ADMINDASHBOARDDATA,
  totalDataAmount: data.totalData,
  orderTrendData: data.monthOrder,
  orderSortData: data.typePercent,
});

export const getAdminDashboardData = () => {
  return (dispatch) => {
    axios.get('http://localhost:9080/home/dashboard', {
      headers: {
        'Authorization': "Bearer " + localStorage.getItem("access_token")
      }
    }).then((res) => {
      console.log(localStorage.getItem("access_token"));
      dispatch(changeDetail(res.data.data));
    }).catch(()=>{
      console.log('error');
    })
  }
}